<template>
	<div class="container">
		<van-nav-bar
		  left-arrow
		  @click-left="onClickLeft"
		  :border="false"
		>		
		  <van-icon name="arrow-left" slot="left" color="#000" size="20"/>
		  <div slot="title" class="weight_header" style="font-size: 16px;">支付宝提现</div>
	    </van-nav-bar>
	    
       
	    <div class="wrap">
	    	
	    	<div class="title">提现金额</div>
	    	
	    	<div class="selectWrap">
	    		<div class="inputWrap">
	    			<span>¥</span>
	    			<input type="number" class="input" placeholder="请输入提现金额" v-model="params.cashAmount"/>
	    		</div>
	    	</div>	    
	    	
	        <div class="all">
	        	<div>
		        	<span style="margin-right: 5px;color: #999;">您当前可提现最高金额为</span>
		        	<span>¥{{format(max)}}</span>	        		
	        	</div>
                <div style="color: #FB713B;" @click="alling">全部提现</div>
	        </div>
	    	
	    	
	    	<div class="title">提现账户</div>
	    	
	    	<div class="selectWrap">
	    		<div class="inputWrap">
	    			<van-icon name="manager-o" size="16"/>
	    			<input type="text" class="input" placeholder="请输入支付宝账号对应的真实姓名" v-model="params.payName"/>
	    		</div>
	    	</div>	    

	    	<div class="selectWrap">
	    		<div class="inputWrap">
	    			<img src="../../../../../static/img/lanhu/76.png" alt="" style="width: 17px;"/>
	    			<input type="text" class="input" placeholder="请输入支付宝账号" v-model="params.payAccount"/>
	    		</div>
	    	</div>

	        <div class="all">
	        	<div>
		        	<span style="margin-right: 5px;color: #999;">只支持手机号为支付宝账号的用户</span>       		
	        	</div>
	        </div>	    	
	    </div>
	    
	    <div class="tips">由于需要审核，提现预计将在24小时内到账</div>
	    
	    <div class="next" @click="confirm">
	    	<div>确认提现</div>
	    </div>
	    
	    
  
	    

	</div>	
</template>

<script>
import {getFun} from '@/api/publicFun.js'	
let publicFun=getFun()	
export default {	
	data() {
       return {
          url1:this.$api+'/marketorderservice/api/v1/market/userCashOut/addUserCashOut',
          url2:this.$api+'/marketorderservice/api/v1/market/userCashOut/myMoneyInfo/',
          params:{
            payAccount:'' ,  //支付宝账号	
            cashWay:'0',    // 提现方法 
            userId:'',      // 用户ID
            cashAmount:'',   // 提现金额
            payName: "",
          },
          max:'',   // 最高提现记录          
       }
	},
	methods: {	
		confirm(){
			if(!this.params.cashAmount){
		       this.$toast('请输入提现金额')
		       return false				
			}
			let num=Number(this.params.cashAmount)			
		    var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
		    if (!reg.test(num)) {
		       this.$toast('提现金额格式不正确')
		       return false
		    }
			if(!this.params.payAccount){
		       this.$toast('请输入支付宝账号')
		       return false				
			}		    		   
			// 验证支付宝账号
	  		let reg2=/^1[3456789]\d{9}$/
	  		if(!reg2.test(this.params.payAccount)){
	  			this.$toast('只支持手机号为支付宝账号的用户');
	  			return false
	  		}		
	  		// 验证支付宝姓名
			if(!this.params.payName){
		       this.$toast('请输入支付宝姓名')
		       return false				
			}		  		
			if(this.params.cashAmount>this.max){
		       this.$toast('提现金额不足')
		       return false				
			}
			let that=this
			this.$Axios2.Post(this.url1,this.params).then(function(res) {
			   let arg='[{"id":"'+res.data+'"}]' 
			   that.link('/market/withdrawal/progress',arg)
			}) 			
		},
		alling(){
			this.params.cashAmount=this.max
		},
		format(str){
			if(!str){return '0.00'}else{
				str=str.toFixed(2)
				return str				
			}
		},		
        getData(){
          let that=this
		  this.$Axios2.Get(this.url2+this.params.userId).then(function(res) {
              that.max=res.data.myMoney
		  })        	
        },
	},
	mixins:[publicFun],//混入		
	mounted() {
		this.params.userId=this.$router.currentRoute.query.userId	
		this.getData()
	}
}	
</script>

<style scoped="" lang="scss">
*{font-size: 14px;color: #333;font-weight: 500;}
.container{position: absolute;left: 0;top: 0;background: #f8f8f8;min-height: 100%;width: 100%;}
.wrap{background: #fff;}
.title{font-size: 15px;color: #333;padding: 15px;margin-top: 10px;}
.selectWrap{padding: 15px 15px 0;display: flex;align-items: center;}
.inputWrap{display: flex;border-bottom: 1px solid #f0f0f0;width: 100%;padding-bottom: 15px;align-items: center;}
.input{flex: 1;margin-left: 10px;border: none;}
.all{padding: 10px 15px 22px;display: flex;justify-content: space-between;}
.tips{padding: 15px;color: #999;font-size: 12px}
.next{padding: 15px;
  div{background: #FFD630;text-align: center;padding: 12px 0;font-size: 16px}
}
</style>